package errors

import (
	goerrors "github.com/go-errors/errors"
)

const SUCC = "success"

type CustomError struct {
	ErrCode int            `json:"-"`
	Msg     string         `json:"msg"`
	Data    interface{}    `json:"data,omitempty"`
	Err     goerrors.Error `json:"-"`
}

func (err *CustomError) Error() string {
	return err.Err.Error()
}

func (err *CustomError) ErrorStack() string {
	return err.Err.ErrorStack()
}

func (err *CustomError) IsSuccess() bool {
	return err.Msg == SUCC
}

func New(errCode int, e interface{}) *CustomError {
	goerrors.MaxStackDepth = 5
	return &CustomError{
		ErrCode: errCode,
		Err:     *goerrors.New(e),
	}
}
